<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\ChOperationLog;
use App\CustHub\Annotation\ChPermission;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\CorpTagRequest;
use App\CustHub\Service\ChCorpTagService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Mine\MineController;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: 'ch/tag'),ApiAuth,VerifySignature]
class CorpTagController extends MineController
{
    #[Inject]
    protected ChCorpTagService $service;

    #[PostMapping('corpTagList')]
    public function corpTagList(CorpTagRequest $request)
    {
        return $this->success($this->service->corpTagList($request->all()));
    }

    #[PostMapping('personalTagList')]
    public function personalTagList(CorpTagRequest $request)
    {
        return $this->success($this->service->personalTagList($request->all()));
    }

    #[PostMapping('selectList')]
    public function selectList(CorpTagRequest $request): ResponseInterface
    {
        return $this->success($this->service->selectList($request->all()));
    }

    /**
     * 同步企业标签
     * @param CorpTagRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('syncCorpTag'),ChPermission('ch:corp:tag:sync')]
    public function syncCorpTag(CorpTagRequest $request): ResponseInterface
    {
        return $this->service->syncCorpTag($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 同步企业标签
     * @param CorpTagRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('syncPersonalTag'),ChPermission('ch:corp:tag:sync:personal')]
    public function syncPersonalTag(CorpTagRequest $request): ResponseInterface
    {
        return $this->service->syncPersonalTag($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 新增个人标签
     * @param CorpTagRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('save'),ChPermission('ch:corp:tag:add'),ChOperationLog]
    public function save(CorpTagRequest $request): ResponseInterface
    {
        return $this->service->save($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 编辑个人标签
     * @param CorpTagRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('update'),ChPermission('ch:corp:tag:update'),ChOperationLog]
    public function update(CorpTagRequest $request): ResponseInterface
    {
        return $this->service->updateTag($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除个人标签
     * @param CorpTagRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('delete'),ChPermission('ch:corp:tag:delete'),ChOperationLog]
    public function delete(CorpTagRequest $request): ResponseInterface
    {
        return $this->service->deleteTag($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 添加客户
     * @param CorpTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('addContact'),ChOperationLog]
    public function addContact(CorpTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->addContact($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 标签里删除客户
     * @param CorpTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delContact'),ChOperationLog]
    public function delContact(CorpTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->delContact($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 移动标签
     * @param CorpTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('moveContact'),ChOperationLog]
    public function moveContact(CorpTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->moveContact($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 打上新的标签
     * @param CorpTagRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('setCorpTag'),ChOperationLog]
    public function setCorpTag(CorpTagRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->setCorpTag($request->all()) ? $this->success() : $this->error();
    }
}